<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Catch the Falling Boxes</title>
    <style>
        body {
            display: flex;
            flex-direction: column;
            align-items: center;
            font-family: Arial, sans-serif;
            background-color: #f0f0f0;
            margin: 0;
            height: 100vh;
        }

        h1 {
            margin-top: 20px;
        }

        #gameArea {
            position: relative;
            width: 300px;
            height: 500px;
            border: 1px solid #333;
            overflow: hidden;
            background-color: #fff;
        }

        .box {
            position: absolute;
            width: 50px;
            height: 50px;
        }

        #scoreContainer {
            margin-top: 20px;
            font-size: 20px;
        }
    </style>
</head>
<body>
    <h1>Catch the Falling Boxes!</h1>
    <div id="gameArea"></div>
    <div id="scoreContainer">Score: <span id="score">0</span></div>

    <script>
        const gameArea = document.getElementById("gameArea");
        const scoreDisplay = document.getElementById("score");
        let score = 0;

        // Function to create a falling box
        function createBox() {
            const box = document.createElement("div");
            box.classList.add("box");
            box.style.backgroundColor = getRandomColor();
            box.style.left = Math.random() * (gameArea.clientWidth - 50) + "px"; // Random horizontal position
            box.style.top = "0px"; // Start from the top
            gameArea.appendChild(box);
            
            // Animate the box falling
            let fallInterval = setInterval(() => {
                const top = parseInt(box.style.top);
                if (top < gameArea.clientHeight - 50) {
                    box.style.top = (top + 5) + "px"; // Move the box down
                } else {
                    clearInterval(fallInterval);
                    gameArea.removeChild(box); // Remove box if it falls out of the game area
                }
            }, 100);
            
            // Add click event to the box
            box.addEventListener("click", () => {
                score++;
                scoreDisplay.textContent = score;
                clearInterval(fallInterval);
                gameArea.removeChild(box); // Remove box when clicked
            });
        }

        // Function to get a random color
        function getRandomColor() {
            const letters = '0123456789ABCDEF';
            let color = '#';
            for (let i = 0; i < 6; i++) {
                color += letters[Math.floor(Math.random() * 16)];
            }
            return color;
        }

        // Create boxes at intervals
        setInterval(createBox, 1000); // Create a new box every second
    </script>
</body>
</html>